package progetto.gruppo0506;

import java.util.ArrayList;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Point;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;

public class DisegnaPercorso extends Overlay {
	private ArrayList<GeoPoint> pathPoints;

	public DisegnaPercorso(ArrayList<GeoPoint> pathPoints) {
		this.pathPoints = pathPoints;
	}

	@Override
	public boolean draw(Canvas canvas, MapView mapView, boolean shadow,
			long when) {
		super.draw(canvas, mapView, shadow);
		Projection projection = mapView.getProjection();

		Path path = new Path();
		GeoPoint srcGeo;
		GeoPoint dstGeo;

		Paint paint = new Paint();
	    paint.setDither(true); 
	    paint.setColor(Color.RED); 
	    paint.setStyle(Paint.Style.FILL_AND_STROKE); 
	    paint.setStrokeJoin(Paint.Join.ROUND); 
	    paint.setStrokeCap(Paint.Cap.ROUND); 
	    paint.setStrokeWidth(2);  

		for (int i = 0; i < pathPoints.size() - 1; i++) {
			srcGeo = pathPoints.get(i);
			dstGeo = pathPoints.get(i + 1);

			Point srcPoint = new Point();
			projection.toPixels(srcGeo, srcPoint);

			Point dstPoint = new Point();
			projection.toPixels(dstGeo, dstPoint);

			path.moveTo(dstPoint.x, dstPoint.y);
			path.lineTo(srcPoint.x, srcPoint.y);

			canvas.drawPath(path, paint);
		}
		
		return true;
	}
}
